home *** CD-ROM | disk | FTP | other *** search
/ The Atari Compendium / The Atari Compendium (Toad Computers) (1994).iso / files / prgtools / gnustuff / minix / update~4.z / update~4 / lib_stdio__allocbu.c < prev    next >
Encoding:
C/C++ Source or Header  |  1989-09-06  |  1.1 KB  |  48 lines

  1. /*            _ a l l o c b u f
  2.  *
  3.  * Allocate a buffer to a stream. This routine is designed to
  4.  * be called from _flsbuf or _filbuf and hence has some hooks
  5.  * in it for these routines.
  6.  *
  7.  * The routine initialises _bufsiz, _base, _ptr and _ctr. No
  8.  * buffer is allocated if _IONBF is in effect. Line buffering
  9.  * is engaged if the stream is attached to a terminal and the
  10.  * stream is not opened for input.
  11.  *
  12.  * Patchlevel 1.0
  13.  *
  14.  * Edit History:
  15.  */
  16.  
  17. #include "stdiolib.h"
  18.  
  19. /*LINTLIBRARY*/
  20.  
  21. int _allocbuf(fp)
  22.  
  23. FILE *fp;                /* stream */
  24.  
  25. {
  26.   int isatty();                /* channel is tty */
  27. #ifdef __STDC__
  28.   void *malloc(unsigned int);            /* memory allocator */
  29. #else
  30.   void *malloc();            /* memory allocator */
  31. #endif
  32.  
  33.   if (TESTFLAG(fp, _IONBF)) {
  34.     fp->_base   = &fp->_buf;
  35.     fp->_bufsiz = sizeof(fp->_buf);
  36.   }
  37.   else {
  38.     if ((fp->_base = (unsigned char *) malloc((unsigned int)BUFSIZ)) == NULL)
  39.       return -1;
  40.     SETFLAG(fp, _IOMYBUF);
  41.     fp->_bufsiz = BUFSIZ;
  42.     if (! TESTFLAG(fp, _IOREAD) && isatty(fp->_file))
  43.       SETFLAG(fp, _IOLBF);
  44.   }
  45.   INITBUFFER(fp);
  46.   return fp->_bufsiz;
  47. }
  48.